<?php

namespace app\system\controller;

use app\common\base\_Db;
use app\common\controller\CommonController;
use app\common\entity\RequestEntity;
use think\Db;

class Order extends CommonController{
    /*****************机场职工订单*************************/
    /**
     * 订单列表
     */
    public function ListOrder(){
        $param_page = $get_page = input('Page', 1);
        $param_pagesize =  10;
        $get_keyword = new RequestEntity('search_key', '搜索内容', false, 0);
        $array_data_range = explode('|', $get_keyword->text);
        $where = '1=1 and u.iden = 1';
        if(!empty($get_keyword->text)){
            if (is_array($array_data_range) && $array_data_range[0] !== '' && $array_data_range[1] !== '') {
                $where .= " and pay_time between '" . $array_data_range[0] . " 00:00:00'" . " and '" . $array_data_range[1] . " 23:59:59'";
            }
        }
        $res = Db::name('order_info ')->alias('o')
                ->field('o.order_id, o.out_trade_no, o.pay_time, o.pay_money, u.nick_name')
                ->join('user u', 'o.openid = u.openid')
                ->order('o.pay_time desc')
                ->where($where)
                ->limit(($param_page - 1) * $param_pagesize, $param_pagesize)
                ->select();
        foreach ( $res as $key => $value){
            $res[$key]['Order'] = $key + 1;
        }
        $int_total_count = Db::table('order_info')->count();
        $data['tableData']=$res;
        $data['TotalCount'] = $int_total_count;
        $data['Page'] = (int)$param_page;
        $data['PageSize'] = (int)$param_pagesize;
        _Db::ResponseJson($data);
    }
    /**
     * 订单详情
     */
    public function ItemOrder(){
        $OrderId = new RequestEntity('OrderId', '订单id', false, 32);
        $res = Db::name('order_info ')->alias('o')
            ->field('o.order_id, o.out_trade_no, o.pay_time, o.pay_money, o.trade_state, u.nick_name')
            ->join('user u', 'o.openid = u.openid')
            ->where('order_id ="'.$OrderId->text.'"and u.iden = 1')
            ->find();
        _Db::ResponseJson($res);
    }
}